// LaserSound for Processing // Eric Rollins 2009 // Based on samples from MakeController site. // Read analog in from MakeController, output audio. import oscP5.*; import netP5.*; import ddf.minim.*; import ddf.minim.signals.*; Minim minim; AudioOutput out; SineWave sine; OscP5 oscP5; NetAddress makeControllerAddress; OscMessage request0, request4; String analog0, analog4; // Values read from analog inputs. int v0; int v4; // Light level of activation. int threshold; // Frequencies output. int f1, f2, f3, f4; void setup() { threshold = 80; f1 = 524; f2 = 622; f3 = 699; f4 = 784; minim = new Minim(this); // get a line out from Minim, default bufferSize is 1024, default sample rate is 44100, bit depth is 16 out = minim.getLineOut(Minim.STEREO); // create a sine wave Oscillator, set to 440 Hz, at 0.5 amplitude, sample rate from line out sine = new SineWave(f1, 0.8, out.sampleRate()); // set the portamento speed on the oscillator to 200 milliseconds sine.portamento(100); // add the oscillator to the line out out.addSignal(sine); analog0 = "/analogin/0/value"; analog4 = "/analogin/4/value"; v0 = 0; v4 = 0; size(512, 200, P2D); frameRate(25); //start oscP5, listening for incoming messages at port 10000 oscP5 = new OscP5(this, 10000); makeControllerAddress = new NetAddress( "192.168.0.200", 10000 ); request0 = new OscMessage(analog0); request4 = new OscMessage(analog4); println("finished setup"); } void draw() { background(0); oscP5.send(request0, makeControllerAddress); oscP5.send(request4, makeControllerAddress); /* stroke(255); // draw the waveforms for(int i = 0; i < out.bufferSize() - 1; i++) { float x1 = map(i, 0, out.bufferSize(), 0, width); float x2 = map(i+1, 0, out.bufferSize(), 0, width); line(x1, 50 + out.left.get(i)*50, x2, 50 + out.left.get(i+1)*50); line(x1, 150 + out.right.get(i)*50, x2, 150 + out.right.get(i+1)*50); } */ } void oscEvent(OscMessage theOscMessage) { // compare the incoming address to the address we asked for. if( theOscMessage.addrpattern().equals( analog0 ) ) { v0 = theOscMessage.get(0).intValue(); } else if ( theOscMessage.addrpattern().equals( analog4 ) ) { v4 = theOscMessage.get(0).intValue(); } int freq = f4; if( v0 < threshold && v4 < threshold) { freq = f4; } else if (v0 < threshold) { freq = f3; } else if (v4 < threshold) { freq = f2; } else { freq = f1; } sine.setFreq(freq); //println("v0 = " + v0 + " v4 = " + v4 + " freq = " + freq); } void stop() { out.close(); minim.stop(); super.stop(); }